package com.leaf.u_spring.chapter07;

import java.io.IOException;

import org.springframework.context.annotation.Bean;
import org.springframework.core.io.FileSystemResource;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;

public class MultipartConfig {

	/**
	 * 使用Servlet3.0解析multipart请求   
	 * 上传路径和大小见  ServletAndFiterInit
	 * @return
	 * @throws IOException
	 */
	@Bean
	public MultipartResolver multipartResolver_0() throws IOException {
		return new StandardServletMultipartResolver();
	}
	
	/**
	 * 非Servlet3.0容器的替代方案
	 * @return
	 * @throws IOException
	 */
	@Bean
	public MultipartResolver multipartResolver_1() throws IOException {
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
		multipartResolver.setUploadTempDir(new FileSystemResource("/tmp/uploads"));
		multipartResolver.setMaxUploadSize(2097152);
		multipartResolver.setMaxInMemorySize(0);
		return multipartResolver;
	}
}
